/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import util.HibernateUtil;
import java.util.List;
import pojo.Sanpham;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Jackhit
 */
public class SanPhamDAO {
    public List<Sanpham> layDanhSachSanPhamTheoDanhMucCon(int maDanhMucCon) {
        List<Sanpham> dsSanPham = null;
         Session session = null;
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            String hql = "from Sanpham sp where sp.danhMucCon.maDanhMucCon = :maDanhMucCon";
            Query query = session.createQuery(hql);
            query.setInteger("maDanhMucCon", maDanhMucCon);
            dsSanPham = query.list();
         }catch(Exception ex) {
            System.out.println(ex.getMessage());
        }finally {
            session.close();
        }
        return dsSanPham;
    }

    public List<Sanpham> layDanhSachSanPhamTheoDanhMuc(int maDanhMuc) {
        List<Sanpham> dsSanPham = null;
         Session session = null;
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            String hql = "from Sanpham sp where sp.danhMucCon.maDanhMuc = :maDanhMuc";
            Query query = session.createQuery(hql);
            query.setInteger("maDanhMuc", maDanhMuc);
            dsSanPham = query.list();
         }catch(Exception ex) {
            System.out.println(ex.getMessage());
        }finally {
            session.close();
        }
        return dsSanPham;
    }
}
